package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlQuizQuestionStatistics entities. Transaction control of the save(),
 * update() and delete() operations can directly support Spring
 * container-managed transactions or they can be augmented to handle
 * user-managed Spring transactions. Each of these methods provides additional
 * information for how to configure it for the desired type of transaction
 * control.
 * 
 * @see idv.loveloser.dao.MdlQuizQuestionStatistics
 * @author MyEclipse Persistence Tools
 */

public class MdlQuizQuestionStatisticsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlQuizQuestionStatisticsDAO.class);
	// property constants
	public static final String QUIZSTATISTICSID = "quizstatisticsid";
	public static final String QUESTIONID = "questionid";
	public static final String SLOT = "slot";
	public static final String SUBQUESTION = "subquestion";
	public static final String S = "s";
	public static final String EFFECTIVEWEIGHT = "effectiveweight";
	public static final String NEGCOVAR = "negcovar";
	public static final String DISCRIMINATIONINDEX = "discriminationindex";
	public static final String DISCRIMINATIVEEFFICIENCY = "discriminativeefficiency";
	public static final String SD = "sd";
	public static final String FACILITY = "facility";
	public static final String SUBQUESTIONS = "subquestions";
	public static final String MAXMARK = "maxmark";
	public static final String POSITIONS = "positions";
	public static final String RANDOMGUESSSCORE = "randomguessscore";

	public void save(MdlQuizQuestionStatistics transientInstance) {
		log.debug("saving MdlQuizQuestionStatistics instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlQuizQuestionStatistics persistentInstance) {
		log.debug("deleting MdlQuizQuestionStatistics instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlQuizQuestionStatistics findById(java.lang.Long id) {
		log.debug("getting MdlQuizQuestionStatistics instance with id: " + id);
		try {
			MdlQuizQuestionStatistics instance = (MdlQuizQuestionStatistics) getSession()
					.get("idv.loveloser.dao.MdlQuizQuestionStatistics", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlQuizQuestionStatistics instance) {
		log.debug("finding MdlQuizQuestionStatistics instance by example");
		try {
			List results = getSession()
					.createCriteria(
							"idv.loveloser.dao.MdlQuizQuestionStatistics")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlQuizQuestionStatistics instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlQuizQuestionStatistics as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByQuizstatisticsid(Object quizstatisticsid) {
		return findByProperty(QUIZSTATISTICSID, quizstatisticsid);
	}

	public List findByQuestionid(Object questionid) {
		return findByProperty(QUESTIONID, questionid);
	}

	public List findBySlot(Object slot) {
		return findByProperty(SLOT, slot);
	}

	public List findBySubquestion(Object subquestion) {
		return findByProperty(SUBQUESTION, subquestion);
	}

	public List findByS(Object s) {
		return findByProperty(S, s);
	}

	public List findByEffectiveweight(Object effectiveweight) {
		return findByProperty(EFFECTIVEWEIGHT, effectiveweight);
	}

	public List findByNegcovar(Object negcovar) {
		return findByProperty(NEGCOVAR, negcovar);
	}

	public List findByDiscriminationindex(Object discriminationindex) {
		return findByProperty(DISCRIMINATIONINDEX, discriminationindex);
	}

	public List findByDiscriminativeefficiency(Object discriminativeefficiency) {
		return findByProperty(DISCRIMINATIVEEFFICIENCY,
				discriminativeefficiency);
	}

	public List findBySd(Object sd) {
		return findByProperty(SD, sd);
	}

	public List findByFacility(Object facility) {
		return findByProperty(FACILITY, facility);
	}

	public List findBySubquestions(Object subquestions) {
		return findByProperty(SUBQUESTIONS, subquestions);
	}

	public List findByMaxmark(Object maxmark) {
		return findByProperty(MAXMARK, maxmark);
	}

	public List findByPositions(Object positions) {
		return findByProperty(POSITIONS, positions);
	}

	public List findByRandomguessscore(Object randomguessscore) {
		return findByProperty(RANDOMGUESSSCORE, randomguessscore);
	}

	public List findAll() {
		log.debug("finding all MdlQuizQuestionStatistics instances");
		try {
			String queryString = "from MdlQuizQuestionStatistics";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlQuizQuestionStatistics merge(
			MdlQuizQuestionStatistics detachedInstance) {
		log.debug("merging MdlQuizQuestionStatistics instance");
		try {
			MdlQuizQuestionStatistics result = (MdlQuizQuestionStatistics) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlQuizQuestionStatistics instance) {
		log.debug("attaching dirty MdlQuizQuestionStatistics instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlQuizQuestionStatistics instance) {
		log.debug("attaching clean MdlQuizQuestionStatistics instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}